﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;

using ISS.CaseStudy.DAL;
using ISS.CaseStudy.Entities;

namespace ISS.CaseStudy.BLL
{
    public class CaseStudyRelatedInformationBLL
    {
        public static List<string> GetInfoIdsByCaseStudyId(string caseStudyId)
        {
            List<string> relatedIds = new List<string>();

            DataSet dataSet = CaseStudyRelatedInfoDLL.GetInfosByCaseStudyId(caseStudyId);
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                relatedIds.Add(row["RelatedId"].ToString());
            }

            return relatedIds;
        }

        public static List<string> GetInfoIdsByRelatedId(string relatedId)
        {
            List<string> caseStudyIds = new List<string>();

            DataSet dataSet = CaseStudyRelatedInfoDLL.GetInfosByRelatedId(relatedId);
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                caseStudyIds.Add(row["CaseStudyId"].ToString());
            }

            return caseStudyIds;
        }

        public static void UpdateByCaseStudyId(string caseStudyId, List<string> relatedIds)
        {
            CaseStudyRelatedInfoDLL.DeleteByCaseStudyId(caseStudyId);

            foreach (string relatedId in relatedIds)
            {
                CaseStudyRelatedInfo caseStudyRelatedInfo = new CaseStudyRelatedInfo();
                caseStudyRelatedInfo.CaseStudyId = caseStudyId;
                caseStudyRelatedInfo.RelatedId = relatedId;

                CaseStudyRelatedInfoDLL.Insert(caseStudyRelatedInfo);
            }
        }

        public static void UpdateByRelatedId(string relatedId, List<string> caseStudyIds)
        {
            CaseStudyRelatedInfoDLL.DeleteByRelatedId(relatedId);

            foreach (string caseStudyId in caseStudyIds)
            {
                CaseStudyRelatedInfo caseStudyRelatedInfo = new CaseStudyRelatedInfo();
                caseStudyRelatedInfo.CaseStudyId = caseStudyId;
                caseStudyRelatedInfo.RelatedId = relatedId;

                CaseStudyRelatedInfoDLL.Insert(caseStudyRelatedInfo);
            }
        }

        public static void DeleteByCaseStudyId(string caseStudyId)
        {
            CaseStudyRelatedInfoDLL.DeleteByCaseStudyId(caseStudyId);
        }

        public static void DeletedByRelatedId(string relatedId)
        {
            CaseStudyRelatedInfoDLL.DeleteByRelatedId(relatedId);
        }
    }
}
